package org.zhu.service.impl;

import com.youtu.Youtu;
import org.json.JSONException;
import org.springframework.stereotype.Service;
import org.zhu.service.YoutuService;

import java.io.File;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by yingzhi zhu on 2017/10/16.
 */
@Service
public class YoutuServiceImpl implements YoutuService{
    private static final String APP_ID = "10100754";
    private static final String SECRET_ID = "AKIDoU2TlrgWgicMxNwzFMMB3oNmeP3WnCT0";
    private static final String SECRET_KEY = "Zw75wpDXEj174sfLrdHev54raCg6Xotz";
    private static final String USER_ID = "zhu";
    String[] groupId = new String[]{"test"};
    private List<String> group_list = Arrays.asList(groupId);
    private Youtu faceYoutu = new Youtu(APP_ID, SECRET_ID, SECRET_KEY,Youtu.API_YOUTU_END_POINT,USER_ID);



    @Override
    public String delectFace() throws KeyManagementException, NoSuchAlgorithmException, JSONException, IOException {
        return faceYoutu.DetectFace("C:\\Users\\Administrator\\Desktop\\my.jpg",0).toString();
    }

    @Override
    public String createPerson() throws KeyManagementException, NoSuchAlgorithmException, JSONException, IOException {
        File file = new File("C:\\Users\\Administrator\\Desktop\\renlian");
        int x =0;
        for (File file1 :file.listFiles()){

            System.out.println(faceYoutu.NewPerson(file1.getAbsolutePath(),"personp"+x,group_list).toString());
            x++;
        }

//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person2",group_list).toString());
//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person3",group_list).toString());
//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person4",group_list).toString());
//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person5",group_list).toString());
//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person6",group_list).toString());
//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person7",group_list).toString());
//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person8",group_list).toString());
//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person9",group_list).toString());
//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person10",group_list).toString());
//        System.out.println(faceYoutu.NewPerson("C:\\Users\\Administrator\\Desktop\\psb.jpg","person11",group_list).toString());


        return "SUCCESSFUL";
    }

    @Override
    public String addFace() throws KeyManagementException, NoSuchAlgorithmException, JSONException, IOException {
        System.out.println(faceYoutu.AddFace("person1",Arrays.asList(
                "C:\\Users\\Administrator\\Desktop\\zhu23.png"
               )).toString());
        return "SUCCESSFUL";
    }

    @Override
    public String faceidentify() throws KeyManagementException, NoSuchAlgorithmException, JSONException, IOException {
        Long old = System.currentTimeMillis();
        System.out.println(faceYoutu.FaceIdentify("C:\\Users\\Administrator\\Desktop\\renlian\\pp.jpg","test"));
        System.out.println("faceidentify用时："+(System.currentTimeMillis()-old));
        return "SUCCESSFUL";
    }

    @Override
    public String getgroupids() throws KeyManagementException, NoSuchAlgorithmException, JSONException, IOException {
        System.out.println(faceYoutu.GetGroupIds().toString());

        return "SUCCESSFUL";
    }


}
